<?php

declare(strict_types=1);

namespace App\Server;


/**
 * @Description 网络请求类
 * @author wuxian
 * @since 2020-04-15
 */
class CurlApi
{
    protected $network;

    /**
     * @param array $config  基本配置
     * @return null
     */
    public function __construct($config = [], $driver = 'saber')
    {
        switch ($driver)
        {
            case 'guzzle':
                $this->network = make(GuzzleNetwork::class,['config'=>$config]);
                break;
            default:
                $this->network = make(SaberNetwork::class,['config'=>$config]);

        }
        return $this->network;
        
    }

    /**
     * @param string $url  get请求的地址
     * @return array
     */
    public function get($url = '')
    {  
        return $this->network->get($url); 
    }
    /**
     * @param string $url  post请求的地址
     * @param array $data  post请求数据
     * @return array
     */
    public function post($url = '', $data = [])
    {
        return $this->network->post($url, $data);
        
    }

    /** post发送json数据请求
     * @param string $url  post请求的地址
     * @return array
     */
    public function jsonpost($url='',$data=[]){
        return $this->network->jsonpost($url,$data);
    }
}
